<p:config xmlns:p="http://www.orbeon.com/oxf/pipeline" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:oxf="http://www.orbeon.com/oxf/processors" xmlns:xforms="http://www.w3.org/2002/xforms" xmlns:xxforms="http://orbeon.org/oxf/xml/xforms" xmlns:xdb="http://orbeon.org/oxf/xml/xmldb" xmlns:xu="http://www.xmldb.org/xupdate">

	<p:param type="input" name="instance"/>
	
	<p:processor name="oxf:pipeline">
		<p:input name="config" href="../session.xpl"/>
		<p:output name="data" id="session"/>
	</p:processor>

	<!--Add user to defined group-->
	<p:processor name="oxf:xslt">
		<p:input name="data" href="#session"/>
		<p:input name="instance" href="#instance"/>
		<p:output name="data" id="query"/>
		<p:input name="config">
			<xdb:query collection="/db/portal" xsl:version="2.0">
				<xsl:text>xquery version "1.0";</xsl:text>
				update insert element member{
					attribute id{'<xsl:value-of select="/session/username"/>'},
					attribute level{'0'}
				} into /groups/group[@id='<xsl:value-of select="doc('input:instance')/list/group[@join='true']/@id"/>']/members
			</xdb:query>
		</p:input>
	</p:processor>

	<p:processor name="oxf:xmldb-query">
		<p:input name="datasource" href="/config/datasource.xml"/>
		<p:input name="query" href="#query"/>
		<p:output name="data" id="result"/>
	</p:processor>

	<p:processor name="oxf:null-serializer">
		<p:input name="data" href="#result"/>
	</p:processor>

	<p:processor name="oxf:redirect">
		<p:input name="data">
			<redirect-url>
				<path-info>/portal/main/</path-info>
			</redirect-url>
		</p:input>
	</p:processor>
</p:config>